<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="/authtaglib" prefix="auth"%>


<!DOCTYPE html>
<html>
<head>
<title>人员上下船管理</title>
<jsp:include page="/include.jsp" />
<script type="text/javascript">
	
//	$(function() {
		
		
//	var a=	${punchCount};
	//request.getParameter("punchCount");
//		 $("#punchCount").attr("id",a);
//	alert("aaa"+a);
//	}
//	);
	//$(function(){
		
			
	//var monitorMassage ="${monitorMassage}";
	//if(monitorMassage ==""){
	//alert("----++++++!!!");
//}else{
	// $.messager.show({title: '提示', msg: monitorMassage});
	
//	$
	//			.ajax({
		//			url : '${pageContext.request.contextPath}/cnbdw/employeeAction!setIndex.action',
	//				dataType : 'json',
		//			data:{monitorMassage:monitorMassage},
	//			success : function(result) {
						
	//					$
	//			.ajax({
	//				url : '${pageContext.request.contextPath}/cnbdw/employeeAction!closeSession.action',
	//				dataType : 'json',
					
	//				success : function(result) {
	//					}
	//			});
	
						
						
	//					}
	//			});
	
	
//}
//	});
	$(document).ready(function(){
    var a=${punchCount};
    var b=${noPunchCount};
    $("#punchCount").val(a);
     $("#noPunchCount").val(b);
});
	
	function punch(operate) {
		var row = $('#datagrid').datagrid('getSelected')
		if (row == null) {
			$.messager.alert('温馨提示', '请选中一个需要' + (operate == 1 ? '上船' : '下船')
					+ '的人员');
			return;
		}

		if (operate == row.punch) {
			$.messager.alert('温馨提示', '当前人员已' + (operate == 1 ? '上船' : '未上船')
					+ '，请不要重复操作');
			return;
		}

		$.messager.progress({
			title : '提示',
			text : '正在保存，请稍候 ....'
		});
		$
				.ajax({
					url : '${pageContext.request.contextPath}/cnbdw/employeeAction!punch.action',
					dataType : 'json',
					data : {
						id : row.id,
						punch : operate
					},
					success : function(result) {
						try {
							if (result.returnFlag) {
							//	$('#datagrid').datagrid('reload');
						//opener.location.reload();
						window.location.reload();
								d.dialog('destroy');
							}
							$.messager.show({
								title : '提示',
								msg : result.returnMsg
							});
						} catch (e) {
						}
					},
					complete : function() {
						$.messager.progress('close');
					}
				});
	}
	
	function startMonit(id) {
    window.top.$.messager.confirm('提示', '是否确定监视此人员？', function (b) {
        if (b) {
            $.ajax({
                url: '${pageContext.request.contextPath}/cnbdw/employeeAction!startMonitor.action',
                dataType: 'json',
                data: {id: id},
                success: function (data) {
                    $.messager.show({title: '提示', msg: data.returnMsg});
                    if (data.returnFlag) {
                        //刷新主列表
                        $('#datagrid').datagrid('reload');
                    }
                }
            });

        }
    });
}
	
	
	
	function endMonit(id) {
    window.top.$.messager.confirm('提示', '是否确定取消监视此人员？', function (b) {
        if (b) {
            $.ajax({
                url: '${pageContext.request.contextPath}/cnbdw/employeeAction!endMonitor.action',
                dataType: 'json',
                data: {id: id},
                success: function (data) {
                    $.messager.show({title: '提示', msg: data.returnMsg});
                    if (data.returnFlag) {
                        //刷新主列表
                        $('#datagrid').datagrid('reload');
                    }
                }
            });

        }
    });
}
	
	
	
	//执行查询
	function doQuery() {
		if ($("#datasource_query_form").form("validate")) {
			$("#datagrid").datagrid('options').queryParams = serializeObject($('#datasource_query_form')); //把查询条件赋值给datagrid内部变量
			$("#datagrid").datagrid('load'); //重新加载
		}
	}
	//重置查询条件
	function doReset() {
		$('#datasource_query_form').form('reset');
	}
	//页面加载完后响应 onReady
	$(function() {
		//查询按纽绑定事件
		$('#btnQuery').bind('click', doQuery);
		//重置按纽绑定事件
		$('#btnReset').bind('click', doReset);
		//初始化主列表
		$('#datagrid')
				.datagrid(
						{
							url : '${pageContext.request.contextPath}/cnbdw/employeeAction!getPunchAllDatasourceList.action',
							fit : true,
							border : false,
							fitColumns : true,
							pagination : true,
							pageList : [30],
							rownumbers : false,
							sortName : 'id',
							sortOrder : 'desc',
							striped : true,
							columns : [ [
									//{field: 'id', title: '唯一编号', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
									{
										field : 'photo',
										title : '照片',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if ($.trim(value) != '') {
												return '<img src="${pageContext.request.contextPath}' + value + '" style="width: 30px; height: 30px;">';
											}
											return '--';
										}
									},
									{
										field : 'name',
										title : '姓名',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == '') {
												return '--'
											}
											return value;
										}
									},
									//{field: 'namePy', title: 'namePy', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
									{
										field : 'gender',
										title : '性别',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == 1) {
												return '男'
											} else {
												return '女'
											}
											return value;
										}
									},
									{
										field : 'company',
										title : '单位',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == '') {
												return '--'
											}
											return value;
										}
									},
									//   {field: 'duties', title: '政务', align: 'left', formatter: function (value, rowData, rowIndex) {
									//        if (value == '1') {
									//           return '长官'
									//      } else{
									//         return '士兵'
									//      }
									//      return value;
									//   }},
									{
										field : 'cardType',
										title : '证件类型',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == 1) {
												return '身份证'
											} else if (value == 2) {
												return '军官证'
											}
											return value;
										}
									},
									{
										field : 'cardNo',
										title : '证件号码',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == '') {
												return '--'
											}
											return value;
										}
									},
									 {field: 'namePy', title: '是否监视', align: 'left', formatter: function (value, rowData, rowIndex) {
									     if (value == 1) {
									         return '是'
									     }else {
									     return "否";}
									  }},
									{
										field : 'punch',
										title : '上船',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == 1) {
												return '<span style="color:green;"><b>已上船</b></span>'
											} else {
												return '<span style="color:red;"><b>未上船</b></span>'
											}
											return value;
										}
									},
									{
										field : 'punchTime',
										title : '上船时间',
										align : 'left',
										formatter : function(value, rowData,
												rowIndex) {
											if (value == '') {
												return '--'
											}
											return value;
										}
									},
									{field: 'action', title: '人员操作', align: 'left',
                    formatter: function (value, row, index) {
                        var html = "";
                        <auth:button authUrl="cnbdw/employeeAction!startMonitor.action">
                        html += '<span  style="cursor:pointer" onclick="startMonit(\'' + row.id + '\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="开启监视" alt="开启监视"/>开启监视</span>';
                        </auth:button>
                        <auth:button authUrl="cnbdw/employeeAction!endMonitor.action">
                        html += '<span style="cursor:pointer" onclick="endMonit(\'' + row.id + '\')"><img src="${pageContext.request.contextPath}/images/icons/delete.png" title="关闭监视" alt="关闭监视" style="margin-top:2px;">关闭监视</span>';
                        </auth:button>
                        return html;
                    }
                }
									
									 ] ],
							toolbar : '#datagrid_toobar'
						});
	});
</script>
</head>
<body class="easyui-layout">
	<form id="datasource_query_form" method="post">
		<div data-options="region:'north'"
			style="height:60px;border-bottom:none;border-top:none;">
			<table border="0" cellpadding="0" cellspacing="0" height="100%" width="50%">
				<tr>
					<td style="width:1%;text-align:left;" nowrap="nowrap"
						class="tr_left"><label for="datasource_datsourcename">人员名称：</label>
					</td>
					<td style="width:1%;text-align:left;" nowrap="nowrap"><input
						type="text" id="datasource_datsourcename" name="ename"
						class="easyui-validatebox"
						data-options="validType:'specialCharFilter'" /></td>
					
					<td colspan="2" style="width:10%;text-align:left;" nowrap="nowrap">
						<input type="button" id="btnQuery" value="查 询" class="search_btn" />
						<input type="button" id="btnReset" value="重 置" class="reset_btn" />
					</td>
				</tr>
			</table>
		</div>
		<div data-options="region:'center'" style="border-top:none">
			<table id="datagrid"></table>
			<div id="datagrid_toobar" class="etl_panel_title">
				<auth:button authUrl="cnbdw/employeeAction!add.action">
					<a href="javascript:void(0);" onclick="punch(1)"
						class="easyui-linkbutton"
						data-options="iconCls:'icon-tip',plain:true" style="float:left;">上船</a>
				</auth:button>
				<div class="datagrid-btn-separator"></div>
				<auth:button authUrl="cnbdw/employeeAction!delete.action">
					<a href="javascript:void(0);" onclick="punch(0)"
						class="easyui-linkbutton"
						data-options="iconCls:'icon-tip',plain:true">下船</a>
				</auth:button>
				 <span class="tr_left">当前在船人数 <input id="punchCount" style="width:30px ;text-align:right; text-color:red; " readonly="readonly" ></input> 人
				</span> 
				<span class="tr_left">当前离船人数 <input id="noPunchCount" style="width:30px;text-align:right;" readonly="readonly"></input> 人
				</span>
				
			</div>
		</div>

		</div>

	</form>

</body>
</html>

